package com.shoeshopping.service.joseph;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import com.shoeshopping.dao.BaseDao;
import com.shoeshopping.dao.joseph.GoodsDao;
import com.shoeshopping.entity.Goods;

@Service("goodsService")
public class GoodsServiceImpl implements GoodsService {
	@Resource(name="baseDao")
	private BaseDao baseDao;
	
	@Override
	public List displayAllGoods() {
		String hql = "from Goods";
		return baseDao.find(hql);
	}

	@Override
	public List displayGoodsByType(String type) {
		String hql = "from Goods where type = ?";
		List param = new ArrayList();
		param.add(type);
		return baseDao.find(hql, param);
	}
	
	@Override
	public Goods displayGoodsById(String id) {
		String hql = "from Goods where id=?";
		List param = new ArrayList();
		param.add(id);
		
		List goodsList = baseDao.find(hql, param);
		if(goodsList==null||goodsList.size()<=0)
			return null;
		return (Goods)goodsList.get(0);
	}
	
	@Override
	public Goods displayGoodsByNameAndColor(String name, String color) {
		String hql = "from Goods where name=? and color=?";
		List param = new ArrayList();
		param.add(name);
		param.add(color);
		
		List goodsList = baseDao.find(hql, param);
		if(goodsList==null||goodsList.size()<=0)
			return null;
		return (Goods)goodsList.get(0);
	}
	public BaseDao getBaseDao() {
		return baseDao;
	}

	public void setBaseDao(BaseDao baseDao) {
		this.baseDao = baseDao;
	}
}
